﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SalePartial.BLL;
using SalePartial.Model;
using SalePartial.Utility;

public partial class Management_Moderation_ChargeUserVerified : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginUserType type = RoleControlManager.checkUserAuthority(User.Identity.Name);
        if (type != LoginUserType.ADMIN)
        {
            Response.Redirect(GlobalSetting.UrlHomePage, true);
        }
    }


    protected void rgridBuyers_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        //Session["UserName"]?? user.Identity.Name???
        string loginUser = User.Identity.Name;
        //★★★★★テストため★★★★★★★
        //string loginUser = "jianglanshui@gmail.com";
        
        Guid companyid;
        int result = 0;
        switch (e.CommandName)
        {
            case "approve":
                companyid = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"];
                result = ModerateBLL.ModerateBuyer(loginUser, companyid, ModerateAction.Approve,"");

                if (result > 0)
                {
                    //success
                    e.Item.OwnerTableView.Rebind();

                }
                else
                {
                }
                break;
            case "reject":
                
                companyid = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"];
                 result = ModerateBLL.ModerateBuyer(loginUser, companyid, ModerateAction.Reject,"");

                if (result > 0)
                {
                    //success
                    e.Item.OwnerTableView.Rebind();

                }
                else
                {
                }

                break;
            case "validateop":
                 companyid = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"];

                XPCompany company = new XPCompany();
            try {
                XPCompanyInfo compInfo = company.GetXPCompany(companyid);

                compInfo.OfficePhoneValidate = !compInfo.OfficePhoneValidate;
                company.Update(compInfo);

            } 
            catch (Exception ex) 
            {
            }
            e.Item.OwnerTableView.Rebind();
            break;
        }
    }


    protected void rgridVendors_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        string loginUser = User.Identity.Name;
        //★★★★★テストため★★★★★★★
        //string loginUser = "jianglanshui@gmail.com";
        Guid companyid;
        int result;
        switch (e.CommandName)
        {
            case "approve":
                companyid = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"];
                result = ModerateBLL.ModerateVendor(loginUser,companyid, ModerateAction.Approve,"");

                if (result > 0)
                {
                    //success
                    e.Item.OwnerTableView.Rebind();

                }
                else
                {
                }

                break;
            case "reject":
                companyid = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"];
                result = ModerateBLL.ModerateVendor(loginUser,companyid, ModerateAction.Reject, "");

                if (result > 0)
                {
                    //success
                    e.Item.OwnerTableView.Rebind();

                }
                else
                {
                }

                break;
            case "validateop":
                companyid = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"];

               XPCompany company = new XPCompany();
                try {
                    XPCompanyInfo compInfo = company.GetXPCompany(companyid);

                    compInfo.OfficePhoneValidate = !compInfo.OfficePhoneValidate;
                    company.Update(compInfo);
                } 
                catch (Exception ex) 
                {
                }
                e.Item.OwnerTableView.Rebind();
                break;
            case "downloadfile":

                break;

        }
    }


    protected void rgridInquiry_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        string loginUser = User.Identity.Name;
        int result;

        switch (e.CommandName)
        {
            case "approve":
                Guid inquiryId = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["InquiryID"];

                result = ModerateBLL.ModerateInquiry(loginUser, inquiryId, InquiryStatus.Approve);
                if (result > 0)
                {
                    //success
                    e.Item.OwnerTableView.Rebind();

                }
                else
                {
                }

                break;
            case "reject":
                Guid companyid = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"];

                result = ModerateBLL.ModerateInquiry(loginUser, companyid, InquiryStatus.Reject);

                if (result > 0)
                {
                    //success
                    e.Item.OwnerTableView.Rebind();

                }
                else
                {
                }

                break;
        }
    }
}